package com.ayusummer.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import com.ayusummer.entity.Login;
import com.ayusummer.service.LoginService;
import com.ayusummer.service.RegisterService;

import java.util.Map;
@RequestMapping("RegisterController")
@Controller//注解，表明是Controller
public class RegisterController {
    @Autowired
    @Qualifier("registerService")
    RegisterService registerService;
    @Autowired
    @Qualifier("loginService")
    LoginService loginService;
    //判断是否登录
    @RequestMapping(value = "homePage")
    public String homePage(Login login, Map<String, Object> map) {
        if(login.getUsername() != "" && login.getPassword() != ""){
            int i = loginService.doLogin(login);
            if (i > 0) {
                //要设置弹窗
                return "registererror";
            } else {
                registerService.doRegister(login);
                map.put("login", login);
                return "redirect:/studentController/getAllStudent";
            }
        }
        else{
            return "error";
        }
    }

}
